<?php
//首先要做权限判断，判断是不是管理员
session_start();
if (!isset($_SESSION['admin']) or $_SESSION['admin'] != 1) { //说明未登录
    echo "<script>alert('只有管理员才能访问本页面！');location.href='login.html';</script>";
    exit;
}
//程序到这里说明权限OK
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>日志查看</title>
</head>
<body>
<style>
    h1 {
        text-align: center
    }

    .s {
        margin-right: 20px
    }

    .require {
        color: red;
    }

    table a {
        color: #2aabd2;
        text-decoration: none
    }

    table a:hover {
        text-decoration: underline;
        color: #761c19
    }
</style>
<h1>日志查看<span style="font-size: 16px;padding-left:20px ;"><a href="index.php" style="color: #1b6d85">返回首页</a></span>
</h1>
<?php
include_once "conn.php";
$sql = "SELECT
	log.*,
	userinfo.username uName
FROM
	userinfo,
	log 
WHERE
	userinfo.id = log.userID 
ORDER BY
	id DESC ";
$result = mysqli_query($conn, $sql);
?>
<table width="80%" cellpadding="10" align="center" border="1" bordercolor="black" style="border-collapse: collapse">
    <tr align="center">
        <td>序号</td>
        <td>用户名</td>
        <td>登录时间</td>
        <td>登录IP</td>
    </tr>
    <?php
    $i = 1;
    while ($info = mysqli_fetch_array($result)){
    ?>
    <tr>
        <td><?php echo $i;?></td>
        <td><?php echo $info['uName'];?></td>
        <td><?php echo date("Y-m-d H:i:s",$info['loggedTime']);?></td>
        <td><?php echo $info['ip'];?></td>
    </tr>
    <?php
        $i ++ ;
    }
    ?>
</table>
<?php

?>
</body>
</html>